package com.kool.devops.service;

import com.kool.core.exception.AppException;
import com.kool.core.util.PropertyUtils;
import com.kool.devops.domain.ExcelToSql;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

/**
 * @description: 开发工具服务类
 * @author: tianhe
 * @create: 2018/11/10 21:11
 */
@Service
public class DevService {
    private static Logger log = Logger.getLogger(DevService.class);

    public String genSql(MultipartFile file) throws AppException {

        if (!file.isEmpty()) {
            try {
                InputStream inputStream = file.getInputStream();

                //模板路径
                String templatePath = PropertyUtils.getValue("TEMPLATE");

                ExcelToSql creater = new ExcelToSql();
                String sql = creater.generate(inputStream, file.getOriginalFilename(), templatePath);
                return sql;
            } catch (IOException e) {
                log.error("", e);
                throw new AppException("");
            }
        }
        return null;
    }
}
